﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace BanHangCshap.Class
{
    class NhomNguoiDung:Database
    {
        #region ***** Fields & Properties *****
        private int _manhomnd;
        public int manhomnd
        {
            get
            {
                return _manhomnd;
            }
            set
            {
                _manhomnd = value;
            }
        }
        private string _tennhomnd;
        public string tennhomnd
        {
            get
            {
                return _tennhomnd;
            }
            set
            {
                _tennhomnd = value;
            }
        }
        #endregion

        #region ***** Init Methods *****
        public NhomNguoiDung()
        {
        }
        public NhomNguoiDung(int manhomnd)
        {
            string sql = "select * from NhomNguoiDung where manhomnd = " + manhomnd + "";
            foreach (DataRow dr in getDataTable(sql).Rows)
            {
                this.manhomnd = manhomnd;
                this.tennhomnd = dr["tennhomnd"].ToString().Trim();
            }
        }
        public NhomNguoiDung(int manhomnd, string tennhomnd)
        {
            this.manhomnd = manhomnd;
            this.tennhomnd = tennhomnd;
        }
        #endregion
        public double taoMaNhomND()
        {
            string sql = "select max(manhomnd) from NhomNguoiDung";
            return getNumberValue(sql) + 1;
        }
        public Boolean themNhomNguoiDung()
        {
            string sql = "insert into NhomNguoiDung(tennhomnd) values (N'" + tennhomnd + "')";
            return executeQuery(sql);
        }
        public Boolean xoaNhomNguoiDung(int manhomnd)
        {
            string sql = "delete NhomNguoiDung where manhomnd = " + manhomnd + "";
            return executeQuery(sql);
        }
        public Boolean suaNhomNguoiDung()
        {
            string sql = "update NhomNguoiDung set tennhomnd = N'" + tennhomnd + "' where manhomnd = " + manhomnd + "";
            return executeQuery(sql);
        }
        public DataTable layDSNhomND()
        {
            string sql = "select manhomnd,tennhomnd, '' as tendn from NhomNguoiDung ";
            return getDataTable(sql);
        }
        public Boolean isExistNhomND(int manhomnd)
        {
            string sql = "select * from NhomNguoiDung where manhomnd = " + manhomnd + "";
            return isExist(sql);
        }
        public DataTable layDSNguoiDung(int manhond)
        {
            string sql = " select * from NguoiDung where manhomnd = " + manhond + " ";
            return getDataTable(sql);
        }
       
        public DataTable phanQuyen(int manhomnd)
        {
            string sql = "select a.manhomnd,b.macn,tencn from NhomNguoiDung a, ChucNangNhomND b, ChucNang c ";
            sql += "where a.manhomnd = " + manhomnd + " and a.manhomnd = b.manhomnd and b.macn = c.macn";
            return getDataTable(sql);
        }
    }
}
